package live.betterman.api.controller;

import live.betterman.common.model.Result;
import live.betterman.system.service.SysRoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;

@RestController
@RequestMapping("/role-menu")
public class RoleMenuController {
    @Autowired
    private SysRoleMenuService roleMenuService;

    @GetMapping("/menus/{roleId}")
    public Result<Collection<String>> getMenusByRole(@PathVariable String roleId) {
        Collection<String> menus = roleMenuService.getMenus(roleId);
        return Result.success(menus);
    }

    @PostMapping("/save/{roleId}")
    public Result<Boolean> saveRoleMenus(@PathVariable String roleId, @RequestBody Collection<String> menuIds) {
        boolean result = roleMenuService.saveMenus(menuIds, roleId);
        return Result.success(result);
    }
}